Draft
Conversation
Closed
Member
Author
|
Rebased onto master so compare view is much cleaner now. |
|
and other solution would be a Wrapper for a command -
public struct Alias<ClientError: Error>: CommandProtocol {
// [...]
fileprivate init<C: CommandProtocol>(_ command: C, alias: String) where C.ClientError == ClientError {
verb = alias
function = "alias for '${command.verb}': {$command.function}"
run = command.run
usage = command.usage
}
}usage: registry.register(Alias(ListCommand(), alias: "L"))drawback: the alias strings are not defined at the command class |
is it not possible to make the alias as optional, so that it not need to add and it is not a breaking change? |
muescha
reviewed
Jun 18, 2022
muescha
left a comment
There was a problem hiding this comment.
changes to display alias in commands list
| commandsByVerb[command.verb] = CommandWrapper(command) | ||
| // Register command for each additional alias | ||
| for alias in command.aliases { | ||
| commandsByVerb[alias] = CommandWrapper(command) |
There was a problem hiding this comment.
Suggested change
| commandsByVerb[alias] = CommandWrapper(command) | |
| let wrappedCommand = CommandWrapper(command) | |
| wrappedCommand.verb = alias | |
| wrappedCommand.function = "alias for '${command.verb}': {$command.function}" | |
| commandsByVerb[alias] = wrappedCommand |
muescha
reviewed
Jun 18, 2022
| var verb: String { get } | ||
|
|
||
| /// Optional list of additional verbs which can be used to invoke this command. | ||
| var aliases: [String] { get } |
There was a problem hiding this comment.
Suggested change
| var aliases: [String] { get } | |
| var aliases: [String]? { get } |
but let aliases be optional and not defined (null)
PS:
need to add
extension CommandProtocol {
var aliases: [String]? { return nil }
}or do just a default implementation:
extension CommandProtocol {
var aliases: [String] { return [] }
}
``
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #153.
Opening this PR as a draft for discussion. I've got a simple/dumb implementation of aliases working in mas and you can see the behavior below. The
installcommand was given an alias ofi, but thehelpoutput lists theinstallcommand twice.This was achieved by:
CommandProtocol.aliasesModifying the
CommandProtocolis a breaking change and each user of this library would need to add thealiasproperty to every command, even if the command has no aliases. The 2nd item causes the command duplication but could be improved by extending the idea of an alias into the registry and auto-generating the help description with something like:Perhaps a better approach is to register aliases differently instead of modifying the model. Going to think some more about this but welcome any feedback or suggestions.